package graph.views.DrawingForm;

import graph.drawings.GraphDrawing;
import graph.views.IToolboxDrawingAction;

import java.awt.BorderLayout;

import javax.naming.spi.DirStateFactory.Result;
import javax.swing.JPanel;
import javax.swing.JTextArea;

public class DrawingPanel extends JPanel {
	private ToolboxDrawingPanel toolBoxDrawingPanel;
	private CanvasPanel canvasPanel;
	private PropertyPanel propertyPanel;
		
	public DrawingPanel() {
		toolBoxDrawingPanel = new ToolboxDrawingPanel();
		toolBoxDrawingPanel.setToolboxDrawingAction(new ToolBoxDrawingActionListener());
		
		canvasPanel = new CanvasPanel();
		canvasPanel.setDrawingMode(DrawingMode.SELECT);
		
		propertyPanel = new PropertyPanel();
		
		this.setLayout(new BorderLayout());
		
		this.add(toolBoxDrawingPanel, BorderLayout.WEST);
		this.add(propertyPanel, BorderLayout.EAST);
		this.add(canvasPanel, BorderLayout.CENTER);
	}
	
	public GraphDrawing getGraphDrawing() {
		return canvasPanel.getGraphDrawing();
	}
	
	public void setGraphDrawing(GraphDrawing graphDrawing) {
		canvasPanel.setGraphDrawing(graphDrawing);
	}

	private class ToolBoxDrawingActionListener implements IToolboxDrawingAction {

		public ToolBoxDrawingActionListener() {
			
		}
		
		@Override
		public void selectAction() {
			canvasPanel.setDrawingMode(DrawingMode.SELECT);
			System.out.println("selectAction");
		}

		@Override
		public void vertexAction() {
			canvasPanel.setDrawingMode(DrawingMode.VERTEX);
			System.out.println("vertexAction");
		}

		@Override
		public void edgeAction() {
			canvasPanel.setDrawingMode(DrawingMode.EDGE);
			System.out.println("edgeAction");
		}

		@Override
		public void deleteAction() {
			canvasPanel.setDrawingMode(DrawingMode.DELETE);
			System.out.println("deleteAction");
		}
	}

	public void setResult(String result) {
		propertyPanel.setText(result);
	}
}
